package com.lf.web.service.system.role;

import com.lf.data.search.Query;
import com.lf.web.service.ResponseCode;
import com.lf.web.service.ResponseInfo;
import com.lf.web.service.ServiceSupport;
import org.apache.log4j.Logger;

public class RoleRemoveService extends ServiceSupport {

    private static final Logger LOGGER = Logger.getLogger(RoleRemoveService.class);
    private RoleDAO roledao;
    private String id = "";

    public void setRoledao(RoleDAO roledao) {
        this.roledao = roledao;
    }

    public String execute() {
        String id = form.getString("id");
        LOGGER.debug("删除角色：id=" + id);
        ResponseInfo ri = new ResponseInfo();
        Query query = new Query();
        query.eq(Role.PARENT_ID, id);
        int code = 0;
        if (roledao.findOne(query).isEmpty()) {
            query.clear();
            query.idEQ(id);
            query.ne(Role.PARENT_ID, "");
            LOGGER.debug(query);
            roledao.remove(query);
            ri.setCode(ResponseCode.FINISH);
        } else {
            ri.setCode(ResponseCode.REFUSE);
        }
        out(ri);
        return NONE;
    }
}
